package cn.piesat.controller;

import cn.piesat.bean.DisksInfo;
import cn.piesat.util.SystemInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.io.IOException;
import java.text.DecimalFormat;
import java.util.List;

@RestController
@RequestMapping("/disk")
@EnableScheduling
@Slf4j
public class DiskMonitorController {

    private Logger logger = LoggerFactory.getLogger(DiskMonitorController.class);

    private static DecimalFormat df=new DecimalFormat("0.00");


    @Value("${usage}")
    private String usage;

    @RequestMapping("/getDisInfo")
    public List<DisksInfo> get() {
        List<DisksInfo> disksList = SystemInfoUtil.getDisksList();
        disksList.forEach(x -> {
            if (Double.parseDouble(usage)<x.getUsage()){
                logger.info(x.getDirName()+"已经超出"+usage+"请及时处理！");
            }

        });

        return disksList;

    }

}
